package vip.mall.modular.comment.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.mall.common.result.CommonPageResult;
import vip.mall.modular.comment.entity.Comment;
import vip.mall.modular.comment.mapper.CommentMapper;
import vip.mall.modular.comment.params.CommentPageParams;
import vip.mall.modular.comment.service.CommentService;
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Override
    public CommonPageResult pageList(CommentPageParams commentPageParams) {
        LambdaQueryWrapper<Comment> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if(ObjectUtil.isNotEmpty(commentPageParams.getGoodsId()))
            lambdaQueryWrapper.eq(Comment::getGoodsId,commentPageParams.getGoodsId());
        Page<Comment> page=new Page<>(commentPageParams.getPageNum(),commentPageParams.getPageSize());
        Page<Comment> commentPage = this.page(page,lambdaQueryWrapper);
        if(ObjectUtil.isNotNull(commentPage))
            return CommonPageResult.builder()
                    .data(commentPage.getRecords())
                    .pageNum((int) commentPage.getCurrent())
                    .pageSize((int) commentPage.getSize())
                    .total(commentPage.getTotal())
                    .totalPage((int) commentPage.getPages())
                    .build();
        return null;
    }
}
